import request from './request'
import type { blogCategoriesItemType, getBlogListType, getBlogType, commentType, getCommentsType } from '@/types/blog'
/**
 * 获取博客列表数据
 */
export async function getBlogs(page = 1, limit = 10, categoryid = '-1') {
  return (await request.get('/api/blog', {
    params: {
      page,
      limit,
      categoryid
    }
  })) as getBlogListType
}

/**
 * 获取博客分类
 */
export async function getBlogCategories() {
  return (await request.get('/api/blogtype')) as blogCategoriesItemType[]
}

export async function getBlog(id: string) {
  return (await request.get(`/api/blog/${id}`)) as getBlogType
}

/**
 * 提交评论
 */
export async function postComment(commentInfo: commentType) {
  return (await request.post(`/api/comment`, commentInfo)) as commentType
}

export async function getComments(blogid: string, page = 1, limit = 10) {
  return (await request.get('/api/comment', {
    params: {
      blogid,
      page,
      limit
    }
  })) as getCommentsType
}
